(一) Server端安装xdebug:
Windows服务器
For windows的xdebug都是预编译好的binary包, 根据PHP版本下载对应的xdebug: 下载地址
Linux服务器
(1) 安装
最简单的安装方法是通过PECL安装: pecl install xdebug
如果你的服务器上没有PECL, 可以通过源码编译安装xdebug:
- 在(http://xdebug.org/download.php#releases)下载source
- 解压源码包:
tar -xzf xdebug-2.2.5.tgz, andcd xdebug-2.2.5 - 继续终端执行:
phpize, and then./configure --enable-xdebug,make && make install
(2) 配置
编辑服务端的php.ini, 增加:
zend_extension="/usr/local/php/modules/xdebug.so" |
(3) 测试xdebug server
重启web server, 然后新建一个test.php, 内容<?php phpinfo(); ?>, 如果访问这个test.php能看到xdebug相关, 说明安装完成.
(二)PC端安装xdebug client
浏览器设置
Chrome安装”debug helper”, 火狐安装”The easiest Xdebug”, 并在插件在设置IDE Key为”PHPSTORM” (这里名字随便设, 但是记住要与IDE里的设置一致).
IDE设置
这里xdebug client根据你的IDE有多个版本可以选择: Eclipse , NetBeans, Vim, 选择自己喜欢的开发环境, 下面是Vim设置xdebug的例子, 其他的IDE可以参考链接:
- [Xdebug Client for Phpstorm] (https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html)
- [Xdebug Client for Eclipse] (https://wiki.eclipse.org/Debugging_using_XDebug)
- [Xdebug Client for vim] (http://thorpesystems.com/blog/debugging-php-in-vim/)
在Vim中安装vdebug
- 在_vimrc中增加如下配置:
Bundle 'joonty/vdebug.git' |
执行
:BundleInstall安装vdebugvdebug默认按键:
<F5>: start/run (to next breakpoint/end of script)<F2>: step over<F3>: step into<F4>: step out<F6>: stop debugging<F7>: detach script from debugger<F9>: run to cursor<F10>: toggle line breakpoint
在Vim中使用vdebug
- 在Vim打开test.php并按下F5, 状态栏会提示”Waiting for a connection…”并持续20秒等待, 在20秒之内通过浏览器访问test.php, vdebug会自动定位在test.php第一行.
- 注: 上面的20秒等待时间是通过
timeout参数设置的,break_on_open参数决定是否自动断在脚本第一行 - 如果按下F5后没有反应, 可以尝试在Vim中执行
:python debugger.run(), 看是否有错误提示;